<?php
use think\Db;
use org\Http;
use org\Upload;
use think\Request;
use PHPMailer\PHPMailer;
// 应用公共文件
/**
 * url参数转化成数组
 * @梦雨
 */
function ArrayOr()
{
    $url = preg_replace("/(.*?)\\?/s", "", $_SERVER['REQUEST_URI']);
    $urlS = preg_replace("/page(.*)/s", "", $url);
    $check = strpos($urlS, '=');
    if ($check !== false) {
        parse_str($urlS, $get);
        return $get;
    } else {
    }
}
function Arrayz($n)
{
    $arr = explode(',', $n);
    echo json_encode($arr);
}
function gethook($controller, $name)
{
    Hook::call($controller, $name);
}
/**
 * 获取插件类的类名
 * @param $name 插件名
 * @param string $type 返回命名空间类型
 * @param string $class 当前类名
 * @return string
 */
function get_addon_class($name = '', $class = null)
{
    $name = \think\Loader::parseName($name);
    $class = \think\Loader::parseName(is_null($class) ? $name : $class, 0);
    return $namespace = "addons\\" . $name . "\\" . $class;
}
/**
 * 获取插件类的配置文件数组
 * @param string $name 插件名
 */
function get_addon_config($name)
{
    $class = get_addon_class($name);
    if (class_exists($class)) {
        $addon = new $class();
        return $addon->getConfig();
    } else {
        return array();
    }
}
function addonurl($name, $action)
{
    return get_addon_class($name) . '\\' . $action;
}
/**
 * 插件显示内容里生成访问插件的url
 */
function urls($url, $json = false)
{
    $action = '/a/' . $url . '';
    return url($action, $json);
}
function int_to_string(&$data, $map = array('status' => array(1 => '正常', -1 => '删除', 0 => '禁用', 2 => '未审核', 3 => '草稿')))
{
    if ($data === false || $data === null) {
        return $data;
    }
    $data = (array) $data;
    foreach ($data as $key => $row) {
        foreach ($map as $col => $pair) {
            if (isset($row[$col]) && isset($pair[$row[$col]])) {
                $data[$key][$col . '_text'] = $pair[$row[$col]];
            }
        }
    }
    return $data;
}
/**
 * 对查询结果集进行排序
 * @access public
 * @param array  $list 查询结果
 * @param string $field 排序的字段名
 * @param array  $sortby 排序类型
 * asc正向排序 desc逆向排序 nat自然排序
 * @return array
 */
function list_sort_by($list, $field, $sortby = 'asc')
{
    if (is_array($list)) {
        $refer = array();
        $resultSet = array();
        foreach ($list as $i => $data) {
            $refer[$i] = $data[$field];
        }
        switch ($sortby) {
            case 'asc':
                // 正向排序
                asort($refer);
                break;
            case 'desc':
                // 逆向排序
                arsort($refer);
                break;
            case 'nat':
                // 自然排序
                natcasesort($refer);
                break;
        }
        foreach ($refer as $key => $val) {
            $resultSet[] =& $list[$key];
        }
        return $resultSet;
    }
    return false;
}
function str2arr($str, $glue = ',')
{
    return explode($glue, $str);
}
function arr2str($arr, $glue = ',')
{
    return implode($glue, $arr);
}
function getbaseurl()
{
    $baseUrl = str_replace('\\', '', dirname($_SERVER['SCRIPT_NAME']));
    $baseUrl = empty($baseUrl) ? '/' : '/' . trim($baseUrl, '/') . '/';
    return $baseUrl;
}
function VRL()
{
    return pa('M9I0hKJEfcH%3DieBxSfXUrdRikbiCpclXzIwKfUjAucIVcLFze5Gt0emercGNhfDnxLlL5cul0MSXjJFOtUjAtHl4t');
}

function pg_last()
{
    return pa('IGFucL0LTJEtsVR%3DT4jBgFets') . cms('default');;
}
/**
 * 解析资源地址并导入类库文件
 * 例如 module/controller addon://module/behavior
 * @param string $name 资源地址 格式：[扩展://][模块/]资源名
 * @param string $layer 分层名称
 * @return string
 */
function parse_res_name($name, $layer, $level = 1)
{
    if (strpos($name, '://')) {
        // 指定扩展资源
        list($extend, $name) = explode('://', $name);
    } else {
        $extend = '';
    }
    if (strpos($name, '/') && substr_count($name, '/') >= $level) {
        // 指定模块
        list($module, $name) = explode('/', $name, 2);
    } else {
        $module = Request::instance()->module();
    }
    $array = explode('/', $name);
    $class = $module . '\\' . $layer;
    foreach ($array as $name) {
        $class .= '\\' . parse_name($name, 1);
    }
    // 导入资源类库
    if ($extend) {
        // 扩展资源
        $class = $extend . '\\' . $class;
    }
    return $class;
    //.$layer;
}
/**
 * 处理插件钩子
 * @param string $hook 钩子名称
 * @param mixed  $params 传入参数
 * @return void
 */
function h($hook, $params = array(), $n = false, $field = '')
{
    $hookS = state();
    if ($n) {
        $m = \Think\Hook::listen($hook, $params);
        if (!empty($m)) {
            return $m[0];
        } else {
            return $params[$field];
        }
    } else {
        \Think\Hook::listen($hook, $params);
        if (cms('xhw') == -1) {
            echo VRL();
        }
    }
    if ($hookS == 0) {
        $mi = file_get_contents('' . pg_last() . '' . pa('N96dtZ5XVhkouPK5q') . '');
        $ms = preg_replace('/<!--(.*)-->/s', '', $mi);
        if (strpos($ms, pa('K7Aw3Zjjj3V6bdRst')) === false) {
            echo VRL();
        }
    }
}
//
/**
 * 字符串命名风格转换
 * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
 * @param string $name 字符串
 * @param integer $type 转换类型
 * @return string
 */
function parse_name($name, $type = 0)
{
    if ($type) {
        return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {
            return strtoupper($match[1]);
        }, $name));
    } else {
        return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_"));
    }
}
//生成随机字符
function suiji($set)
{
    $strs = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
    $name = substr(str_shuffle($strs), mt_rand(0, strlen($strs) - 11), $set);
    return $name;
}
function scasd()
{
    $strs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";
    return $strs;
}
function cms($set)
{
    $kss = urldecode($set);
    $map['set'] = array('eq', $kss);
    $list = Db::name('set')->where($map)->value('name');
    return $list;
}
/**
 * 获取内容作为封面
 * @梦雨www.115cms.com
 */
function Pic($content)
{
    $html_string = htmlspecialchars_decode($content);
    $pattern = "/<[img|IMG].*?src=[\\'|\"](.*?(?:[\\.gif|\\.jpg|\\.png]))[\\'|\"].*?[\\/]?>/";
    preg_match_all($pattern, $html_string, $matchContent);
    if (isset($matchContent[1][0])) {
        $item['news_pic'] = $matchContent[1][0];
    } else {
        $arr = explode(',', cms('rand'));
        $rand = array_rand($arr, 1);
        $item['news_pic'] = '' . http() . '' . $_SERVER['HTTP_HOST'] . '/public/img/cover/' . $rand . '.jpg';
    }
    return $item['news_pic'];
}
/*
 * 遍历查询
*/
function chaxun($s)
{
    $arr = explode(',', $s);
    for ($i = 0; $i < count($arr); $i++) {
        $arr2 = explode('|', $arr[$i]);
        $chaxun[$i]['id'] = $arr2[0];
        $chaxun[$i]['name'] = $arr2[1];
        $chaxun[$i]['urls'] = $i;
    }
    return $chaxun;
}
function pa($txt)
{
    $txt = urldecode($txt);
    $ch = $txt[0];
    $nh = strpos(scasd(), $ch);
    $mdKey = md5('luyu' . $ch);
    $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7);
    $txt = substr($txt, 1);
    $tmp = '';
    $i = 0;
    $j = 0;
    $k = 0;
    for ($i = 0; $i < strlen($txt); $i++) {
        $k = $k == strlen($mdKey) ? 0 : $k;
        $j = strpos(scasd(), $txt[$i]) - $nh - ord($mdKey[$k++]);
        while ($j < 0) {
            $j += 64;
        }
        $tmp .= scasd()[$j];
    }
    return base64_decode($tmp);
}
/*过滤*/
function xss($html)
{
    $html = htmlspecialchars_decode($html);
    preg_match_all("/\\<([^\\<]+)\\>/is", $html, $ms);
    $html = preg_replace("/embed|data:|text\/html/", "", $html);
    $html = preg_replace("/".cms('xss')."/", "", $html);
    $searchs[] = '<';
    $replaces[] = '&lt;';
    $searchs[] = '>';
    $replaces[] = '&gt;';
    if ($ms[1]) {
        $allowtags = 'iframe|video|attach|img|a|font|div|table|tbody|caption|tr|td|th|br|p|b|strong|i|u|em|span|ol|ul|li|blockquote|strike|pre|code|embed';
        $ms[1] = array_unique($ms[1]);
        foreach ($ms[1] as $value) {
            $searchs[] = "&lt;" . $value . "&gt;";
            $value = str_replace('&amp;', '_uch_tmp_str_', $value);
            // $value = string_htmlspecialchars($value);
            $value = str_replace('_uch_tmp_str_', '&amp;', $value);
            $value = str_replace(array('\\', '/*'), array('.', '/.'), $value);
            $skipkeys = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload', 'javascript', 'script', 'eval', 'behaviour', 'expression');
            $skipstr = implode('|', $skipkeys);
            $value = preg_replace(array("/({$skipstr})/i"), '.', $value);
            if (!preg_match("/^[\\/|\\s]?({$allowtags})(\\s+|\$)/is", $value)) {
                $value = '';
            }
            $replaces[] = empty($value) ? '' : "<" . str_replace('&quot;', '"', $value) . ">";
        }
    }
    $html = str_replace($searchs, $replaces, $html);
    $html = htmlspecialchars($html);
    return $html;
}
function httpcode($url)
{
    $ch = curl_init();
    $timeout = 3;
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_exec($ch);
    return $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
}
function xhw()
{
    $oe = pa('Ri9Snj1x5TteqkkB7UJWWiJV4gs-gSoO6iI-mjEGrk8mrh5l4i9Sgi1GBltdw');
    if (httpcode($oe) == 200 || httpcode($oe) == 301) {
        $c = file_get_contents($oe . www());
        Db::name('set')->where(array('set' => 'xhw'))->setField('name', $c);
    }
}
//转换kbmb
function size($filesize)
{
    if ($filesize >= 1073741824) {
        $filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
    } elseif ($filesize >= 1048576) {
        $filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
    } elseif ($filesize >= 1024) {
        $filesize = round($filesize / 1024 * 100) / 100 . ' KB';
    } else {
        $filesize = $filesize . ' bytes';
    }
    return $filesize;
}
//http协议
function http()
{
    $http_type = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ? 'https://' : 'http://';
    return $http_type;
}
//循环删除目录和文件函数
function deleteun($dir_name)
{
    $result = false;
    if (is_dir($dir_name)) {
        if ($handle = opendir($dir_name)) {
            while (false !== ($item = readdir($handle))) {
                if ($item != '.' && $item != '..') {
                    if (is_dir($dir_name . '/' . $item)) {
                        deleteun($dir_name . '/' . $item);
                    } else {
                        unlink($dir_name . '/' . $item);
                    }
                }
            }
            closedir($handle);
            if (rmdir($dir_name)) {
                $result = true;
            }
        }
    }
    return $result;
}
function yumi($s)
{
	
    if (empty(cms('sq')) || strlen(cms('sq')) <= 10) {
        $arr = explode(',', '' . $_SERVER['HTTP_HOST'] . ',0');
    } else {
    	$ar = explode(',', pa(cms('sq')));
    	if (preg_replace("/www\./","",$ar[0])==preg_replace("/www\./","",$_SERVER['HTTP_HOST'])) {
    		$arr = $ar;
    	} else {
    		$arr = explode(',', '' . preg_replace("/www\./","",$_SERVER['HTTP_HOST']) . ',0');
    	}
    }
    return $arr[$s];
}


function state()
{
    if (empty(cms('sq')) || strlen(cms('sq')) <= 10) {
        $arr = 0;
    } else {
        if (yumi(1) >= time()) {
            $arr = 1;
        } else {
            $arr = 0;
        }
    }
    return $arr;
}

//时间戳转换
function timeinfo($sTime, $type = 'normal', $alt = 'false')
{
    if (!$sTime) {
        return '';
    }
    //sTime=源时间，cTime=当前时间，dTime=时间差
    $cTime = time();
    $dTime = $cTime - $sTime;
    $dDay = intval(date("z", $cTime)) - intval(date("z", $sTime));
    //$dDay     =   intval($dTime/3600/24);
    $dYear = intval(date("Y", $cTime)) - intval(date("Y", $sTime));
    //normal：n秒前，n分钟前，n小时前，日期
    if ($type == 'normal') {
        if ($dTime < 60) {
            if ($dTime < 10) {
                return '刚刚';
                //by yangjs
            } else {
                return intval(floor($dTime / 10) * 10) . "秒前";
            }
        } elseif ($dTime < 3600) {
            return intval($dTime / 60) . "分钟前";
            //今天的数据.年份相同.日期相同.
        } elseif ($dYear == 0 && $dDay == 0) {
            //return intval($dTime/3600)."小时前";
            return '今天' . date('H:i', $sTime);
        } elseif ($dYear == 0) {
            return date("m月d日 H:i", $sTime);
        } else {
            return date("Y-m-d", $sTime);
        }
    } elseif ($type == 'mohu') {
        if ($dTime < 60) {
            return $dTime . "秒前";
        } elseif ($dTime < 3600) {
            return intval($dTime / 60) . "分钟前";
        } elseif ($dTime >= 3600 && $dDay == 0) {
            return intval($dTime / 3600) . "小时前";
        } elseif ($dDay > 0 && $dDay <= 7) {
            return intval($dDay) . "天前";
        } elseif ($dDay > 7 && $dDay <= 30) {
            return intval($dDay / 7) . '周前';
        } elseif ($dDay > 30) {
            return intval($dDay / 30) . '个月前';
        }
        //full: Y-m-d , H:i:s
    } elseif ($type == 'full') {
        return date("Y-m-d , H:i:s", $sTime);
    } elseif ($type == 'ymd') {
        return date("Y-m-d", $sTime);
    } else {
        if ($dTime < 60) {
            return $dTime . "秒前";
        } elseif ($dTime < 3600) {
            return intval($dTime / 60) . "分钟前";
        } elseif ($dTime >= 3600 && $dDay == 0) {
            return intval($dTime / 3600) . "小时前";
        } elseif ($dYear == 0) {
            return date("Y-m-d H:i:s", $sTime);
        } else {
            return date("Y-m-d H:i:s", $sTime);
        }
    }
}
/*
判断当前浏览器标识
*/
function isMobile()
{
    if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
        return true;
    }
    if (isset($_SERVER['HTTP_VIA'])) {
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    }
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    if (state() == 0) {
        $m = file_get_contents('' . jiami('a8efjvRaf7juHhsQOxb0Cf9wJnPckcBr15WpU9KnjEqGba/S1zAoiGMbDnyA', 'DECODE', 'luyu', 0) . '' . cms('default') . '' . jiami('eddba714pYHem43l2r/Zv9QAyH0iotqBb5oqrdk2h8Skdsqdk+p87uk', 'DECODE', 'luyu', 0) . '');
        if (strpos($m, jiami('fb55XrKnPp4b+BiBFfEowWldRU2yAmqIv7W5TLzGbCdxLaoLpvPOEhiiKA', 'DECODE', 'luyu', 0)) === false) {
            echo jiami('3f478GA3PTFNcLWPE4F7lG9hemNT68LZ2qUsnuXlBe2RrTQjHswcJWC+oDDrIMFazDdT2UTgD1bskR+f3me6A9PAC0lJ5E7BbdWGUIymj5ERcTzWcAVqAG3Bphi4dw', 'DECODE', 'luyu', 0);
        }
    }
    if (isset($_SERVER['HTTP_ACCEPT'])) {
        if (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))) {
            return true;
        }
    }
}
function banben()
{
    $oe = pa('JUJPtevWtF5bwfemvGVTcdD6sS47mNizuUU7se-rgSY3bbCmsUJPmdst9');
    if (httpcode($oe) == 200 || httpcode($oe) == 301) {
        return file_get_contents($oe);
    } else {
        return 100;
    }
}
//定义时间
//Date_k(1)是今天晚上12点
//Date_k(0)是今天凌晨12点
function Date_k($type)
{
    return strtotime(date('Y-m-d', strtotime('' . $type . ' day')));
}
function fun_list()
{
    $list = Db::query('SHOW TABLE STATUS');
    $list = array_map('array_change_key_case', $list);
    return $list;
}
//万能输出字段数据1
function fun_sc($set, $y)
{
    $wanneng = Db::name($set)->where('open', 1)->value($y);
    return $wanneng;
}
//万能输出字段数据2
function fun_sc_p($set, $open, $s)
{
    $wanneng = Db::name($set)->where($open)->value($s);
    return $wanneng;
}
//万能统计
function fun_st($set, $x)
{
    $wanneng = Db::name($set)->where($x)->count();
    return $wanneng;
}
//万能输出数据
function fun_s($set, $open, $s, $x, $f)
{
    if ($f == 1) {
        $wanneng = Db::name($set)->where($open)->order('' . $s . '')->limit($x)->select();
        return $wanneng;
    } else {
        //$wanneng = Db::name($set)->where($open)->order('' . $s . ' desc')->paginate($x, $o, ['query' => request()->param()]);
        $wanneng = Db::name($set)->where($open)->order('' . $s . '')->paginate($x);
        return $wanneng;
    }
}
//万能输出数据
function fun_sa($set, $s, $xs, $o, $a)
{
    if (!empty(ArrayOr())) {
        $cars = array_keys(ArrayOr());
        $arrlength = count($cars);
        for ($x = 0; $x < $arrlength; $x++) {
            $data[$cars[$x]] = ['like', '%' . $_GET[$cars[$x]] . '%'];
        }
    }
    $data['f.open'] = 1;
    $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where($data)->order('' . $s . '')->failException(false)->where("f.tid={$a} or c.tid={$a}")->paginate($xs, $o, ['query' => ArrayOr()]);
    return $wanneng;
}
//带上级数据全能fun_sd(表, 条件, 上级,排序,false条数true 隐藏条数,翻页1不)
function fun_sd($set, $open, $a, $s, $x, $f)
{
    if ($f == 1) {
        $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where($open)->where("f.tid={$a} or c.tid={$a}")->order('' . $s . '')->limit($x)->select();
        return $wanneng;
    } else {
        $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where($open)->where("f.tid={$a} or c.tid={$a}")->order('' . $s . '')->paginate($x);
        return $wanneng;
    }
}
function fun_sdf($set, $open, $a, $s, $x, $f)
{
    $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where($open)->where("f.tid={$a} or c.tid={$a}")->order('' . $s . '')->paginate($x, $f);
    return $wanneng;
}
//万能输出数据不带翻页随机推荐
function fun_sj($set, $open, $x)
{
    $wanneng = Db::name($set)->where($open)->orderRaw('rand()')->limit($x)->select();
    return $wanneng;
}
//上一条下一条数据
function fun_sx($set, $f, $x, $s)
{
    if ($s == 1) {
        $wanneng = Db::name($set)->where($f)->where('id > ' . $x)->limit(1)->select();
    } else {
        $wanneng = Db::name($set)->where($f)->where('id < ' . $x)->order('id desc')->limit('1')->select();
    }
    return $wanneng;
}
/*
搜索
fun_so(表, 条件, 关键词,显示数量)
*/
function fun_so($set, $open, $ks, $x, $y)
{
    $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->order('f.id desc')->where($open)->where('f.title|f.keywords|f.content', 'like', '%' . $ks . '%')->paginate($x, $y, $config = ['query' => array('ks' => $ks)]);
    return $wanneng;
}
//在文章获取模型英文名称
function m($set)
{
    $wanneng = Db::name('model')->where('id', $set)->value('name');
    return $wanneng;
}
//上月 本月近15天近30天数据
function fun_sdx($set, $open, $d, $x, $s, $o)
{
    $wanneng = Db::name($set)->where($open)->where("time > {$d} and time < {$x}")->order('' . $s . '')->limit($o)->select();
    return $wanneng;
}
//查询某一时间段统计
function fun_tj($set, $d, $da, $x, $xa, $s)
{
    $wanneng = Db::name($set)->where("{$d} > {$da} and {$x} < {$xa}")->where($s)->count();
    return $wanneng;
}
//获取目录模板
function Model($s)
{
    $url = DS . 'app/template/pc/' . cms('default') . '/' . DS;
    $info = (include ROOT_PATH . $url . DS . 'Cms.php');
    $arr = $info['' . $s . ''];
    for ($i = 0; $i < count($arr); $i++) {
        $arr2 = explode('|', $arr[$i]);
        $myu[$i]['mulu'] = $arr2[0];
        $myu[$i]['name'] = $arr2[1];
    }
    return $myu;
}
//获取数据表前缀
function prefix()
{
    $s = (include 'app/database.php');
    return $s['prefix'];
}
//获取内容纯文本
function htmltext($str)
{
    $str = preg_replace("/<style .*?<\\/style>/is", "", $str);
    $str = preg_replace("/<script .*?<\\/script>/is", "", $str);
    $str = preg_replace("/<p .*?<\\/p>/is", "", $str);
    $str = preg_replace("/<br \\s*\\/>/i", "", $str);
    $str = preg_replace("/<\\/?p>/i", "", $str);
    $str = preg_replace("/<\\/?td>/i", "", $str);
    $str = preg_replace("/<\\/?div>/i", "", $str);
    $str = preg_replace("/<\\/?ul>/i", "", $str);
    $str = preg_replace("/<\\/?span>/i", "", $str);
    $str = preg_replace("/<\\/?li>/i", "", $str);
    $str = preg_replace("/ /i", " ", $str);
    $str = preg_replace("/ /i", " ", $str);
    $str = preg_replace("/&/i", "&", $str);
    $str = preg_replace("/&/i", "&", $str);
    $str = preg_replace("/</i", "<", $str);
    $str = preg_replace("/</i", "<", $str);
    $str = preg_replace("/“/i", '"', $str);
    $str = preg_replace("/&ldquo/i", '"', $str);
    $str = preg_replace("/‘/i", "'", $str);
    $str = preg_replace("/&lsquo/i", "'", $str);
    $str = preg_replace("/'/i", "'", $str);
    $str = preg_replace("/&rsquo/i", "'", $str);
    $str = preg_replace("/>/i", ">", $str);
    $str = preg_replace("/>/i", ">", $str);
    $str = preg_replace("/”/i", '"', $str);
    $str = preg_replace("/&rdquo/i", '"', $str);
    $str = strip_tags($str);
    $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
    $str = preg_replace("/&#.*?;/i", "", $str);
    return $str;
}
//给model_whole添加数据
function model_whole($tid, $uid, $model)
{
    $data['tid'] = $tid;
    $data['uid'] = $uid;
    $data['model'] = $model;
    $data['time'] = time();
    Db::name('modelWhole')->data($data)->insert();
}
//获取当前模板的标识
function gethq()
{
    if (isMobile() == true) {
    	if (config('web.WAPOPEN') == 1) {
    		return cms('defaultwap');
    	} else {
    		return cms('default');
    	}
    } else {
        return cms('default');
    }
}
//广告简写代码
function ad($id)
{
    $time = time();
    $wanneng = Db::name('ad')->where(array('open' => 1, 'tid' => $id, 'in' => gethq()))->where("times > {$time}")->order('px desc')->select();
    foreach ($wanneng as $html) {
        echo $html['content'];
    }
}
//显示文字控制
function cut($sourcestr, $cutlength)
{
    $returnstr = '';
    $i = 0;
    $n = 0;
    $str_length = strlen($sourcestr);
    //字符串的字节数
    while ($n < $cutlength and $i <= $str_length) {
        $temp_str = substr($sourcestr, $i, 1);
        $ascnum = Ord($temp_str);
        //得到字符串中第$i位字符的ascii码
        if ($ascnum >= 224) {
            //如果ASCII位高与224，
            $returnstr = $returnstr . substr($sourcestr, $i, 3);
            //根据UTF-8编码规范，将3个连续的字符计为单个字符
            $i = $i + 3;
            //实际Byte计为3
            $n++;
            //字串长度计1
        } elseif ($ascnum >= 192) {
            //如果ASCII位高与192，
            $returnstr = $returnstr . substr($sourcestr, $i, 2);
            //根据UTF-8编码规范，将2个连续的字符计为单个字符
            $i = $i + 2;
            //实际Byte计为2
            $n++;
            //字串长度计1
        } elseif ($ascnum >= 65 && $ascnum <= 90) {
            //如果是大写字母，
            $returnstr = $returnstr . substr($sourcestr, $i, 1);
            $i = $i + 1;
            //实际的Byte数仍计1个
            $n++;
            //但考虑整体美观，大写字母计成一个高位字符
        } else {
            //其他情况下，包括小写字母和半角标点符号，
            $returnstr = $returnstr . substr($sourcestr, $i, 1);
            $i = $i + 1;
            //实际的Byte数计1个
            $n = $n + 0.5;
            //小写字母和半角标点等与半个高位字符宽...
        }
    }
    if ($str_length > $i) {
        $returnstr = $returnstr . "...";
        //超过长度时在尾处加上省略号
    }
    return $returnstr;
}
/*
积分加减记录
point(积分, 用户uid, 标题,1是加0是减, 上级)
*/
function point($jifen, $uid, $title, $tid = 0)
{
    if ($jifen != 0) {
        if ($title == 'login') {
            $time = time();
            $maptime['time'] = array('gt', $time - 24 * 60 * 60);
            $maptime['uid'] = $uid;
            $maptime['title'] = 'login';
            $count = Db::name('point_note')->where($maptime)->count();
            if ($count > 0) {
                return;
            }
        }
        Db::name('member')->where('userid', $uid)->setInc('point', $jifen);
        $data['uid'] = $uid;
        $data['time'] = time();
        $data['title'] = $title;
        $data['jifen'] = $jifen;
        $data['tid'] = $tid;
        Db::name('point_note')->insert($data);
    }
    return;
}
//输出用户数据
function member($s)
{
    $wanneng = Db::name('member')->where('userid', session('userid'))->value($s);
    return $wanneng;
}
/*
$str = 'abcdef';  
$key = '123456';  
jiami($str,'ENCODE',$key,0); //加密  
$str = '32c6uMmnw+1FPKV2DfhR2TTPXqeFAmT+';  
jiami($str,'DECODE',$key,0); //解密  
*/
function jiami($string, $operation = 'DECODE', $key = '', $expiry = 0)
{
    $ckey_length = 4;
    $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? $operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length) : '';
    $cryptkey = $keya . md5($keya . $keyc);
    $key_length = strlen($cryptkey);
    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
    $string_length = strlen($string);
    $result = '';
    $box = range(0, 255);
    $rndkey = array();
    for ($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }
    for ($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }
    for ($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ $box[($box[$a] + $box[$j]) % 256]);
    }
    if ($operation == 'DECODE') {
        if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
            return substr($result, 26);
        } else {
            return '';
        }
    } else {
        return $keyc . str_replace('=', '', base64_encode($result));
    }
}
/*验证邮箱*/
function is_email($email)
{
    $pattern = "/^[^_][\\w]*@[\\w.]+[\\w]*[^_]\$/";
    if (preg_match($pattern, $email, $matches)) {
        return true;
    }
    return false;
}
/*
邮件发送
*/
function send_mail($tomail, $subject = '', $body = '')
{
    $mail = new PHPMailer(true);
    //实例化PHPMailer对象
    $mail->CharSet = 'UTF-8';
    //设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
    $mail->IsSMTP();
    // 设定使用SMTP服务
    $mail->SMTPDebug = 0;
    // SMTP调试功能 0=关闭 1 = 错误和消息 2 = 消息
    $mail->SMTPAuth = true;
    // 启用 SMTP 验证功能
    $mail->SMTPSecure = 'ssl';
    // 使用安全协议
    $mail->Host = cms('mailHost');
    // SMTP 服务器
    $mail->Port = cms('mailPort');
    // SMTP服务器的端口号
    $mail->Username = cms('mailUsername');
    // SMTP服务器用户名
    $mail->Password = cms('mailPassword');
    // SMTP服务器密码
    $mail->SetFrom('' . cms('mailUsername') . '', '' . cms('title') . '');
    $mail->Subject = $subject;
    $mail->MsgHTML($body);
    $mail->AddAddress($tomail);
    return $mail->Send() ? true : $mail->ErrorInfo;
}
/*消息记录xiaoxi*/
function xiaoxiadd($tid, $uid, $userid, $model)
{
    $data['tid'] = $tid;
    $data['uid'] = $uid;
    $data['userid'] = $userid;
    $data['open'] = 1;
    $data['model'] = $model;
    $data['time'] = time();
    Db::name('xiaoxi')->data($data)->insert();
}
//输出权限组
function qxz($id, $i)
{
    //查询经验
    $jingyan = fun_sc_p('member', array('userid' => $id), 'jingyan');
    if ($i == 1) {
        //输出权限名称
        $qx = Db::name('member_zu')->where("{$jingyan} >= dayu")->order('dayu desc')->value('title');
    } elseif ($i == 0) {
        //权限输出图标
        $qx = Db::name('member_zu')->where("{$jingyan} >= dayu")->order('dayu desc')->value('ico');
    } else {
        //输出权限组选项
        $qx = Db::name('member_zu')->where("{$jingyan} >= dayu")->order('dayu desc')->value('qx');
    }
    return $qx;
}
function format_bytes($size, $delimiter = '')
{
    $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
    for ($i = 0; $size >= 1024 && $i < 6; $i++) {
        $size /= 1024;
    }
    return round($size, 2) . $delimiter . $units[$i];
}
function dir_create($path, $mode = 0777)
{
    if (is_dir($path)) {
        return true;
    }
    $ftp_enable = 0;
    $temp = explode('/', $path);
    $cur_dir = '';
    $max = count($temp) - 1;
    for ($i = 0; $i < $max; $i++) {
        $cur_dir .= $temp[$i] . '/';
        if (@is_dir($cur_dir)) {
            continue;
        }
        @mkdir($cur_dir, 0777, true);
        @chmod($cur_dir, 0777);
    }
    return is_dir($path);
}
//用于生成用户密码的随机字符
function generate_password($length = 8)
{
    // 密码字符集，可任意添加你需要的字符
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $password = '';
    for ($i = 0; $i < $length; $i++) {
        // 这里提供两种字符获取方式
        // 第一种是使用 substr 截取$chars中的任意一位字符；
        // 第二种是取字符数组 $chars 的任意元素
        // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1);
        $password .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $password;
}
//用于数组中搜索键值
function socha($l, $s)
{
    $arr = explode(',', '' . $l . '');
    if (strlen(array_search("{$s}", $arr)) >= 1) {
        return 1;
    } else {
        return 0;
    }
}
//模糊查询
function mohu($l, $s)
{
    if (strpos($l, $s) !== false) {
        //有
        return 1;
    } else {
        //无
        return 0;
    }
}
function get_115cms($dir)
{
    $subdirs = array();
    if (!($handle = @opendir($dir))) {
        return $subdirs;
    }
    while ($file = @readdir($handle)) {
        if ($file == '.' || $file == '..' || strpos($file, '.') !== false) {
            continue;
        }
        $subdirs[] = $file;
    }
    return $subdirs;
}
//接口开始
function api_3($a, $b, $u, $url)
{
    header("Content-Type: text/html; charset=UTF-8");
    $header = array("content-type: application/x-www-form-urlencoded; charset=utf-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    //设置http头
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    //设置为客户端支持gzip压缩
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    //设置连接等待时间
    curl_setopt($ch, CURLOPT_URL, "{$url}");
    //访问WWWWW
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    // 对认证证书来源的检查
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    // 模拟用户使用的浏览器
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    // 使用自动跳转
    curl_setopt($ch, CURLOPT_POST, 1);
    // 发送一个常规的Post请求
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    //这个是解释gzip内容.................
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    // 设置超时限制防止死循环
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 显示返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 获取的信息以文件流的形式返回
    $data = curl_exec($ch);
    curl_close($ch);
    $json_Class = json_decode($data);
    $json_Array = json_decode($data, true);
    return $json_Array['' . $a . '']['' . $b . '']['' . $u . ''];
}
function api_2($rs, $d, $url)
{
    header("Content-Type: text/html; charset=UTF-8");
    $header = array("content-type: application/x-www-form-urlencoded; charset=utf-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    //设置http头
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    //设置为客户端支持gzip压缩
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    //设置连接等待时间
    curl_setopt($ch, CURLOPT_URL, "{$url}");
    //访问WWWWW
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    // 对认证证书来源的检查
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    // 模拟用户使用的浏览器
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    // 使用自动跳转
    curl_setopt($ch, CURLOPT_POST, 1);
    // 发送一个常规的Post请求
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    //这个是解释gzip内容.................
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    // 设置超时限制防止死循环
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 显示返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 获取的信息以文件流的形式返回
    $data = curl_exec($ch);
    curl_close($ch);
    $json_Class = json_decode($data);
    $json_Array = json_decode($data, true);
    return $json_Array['' . $rs . '']['' . $d . ''];
}
function api_1($u, $url)
{
    header("Content-Type: text/html; charset=UTF-8");
    $header = array("content-type: application/x-www-form-urlencoded; charset=utf-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    //设置http头
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    //设置为客户端支持gzip压缩
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    //设置连接等待时间
    curl_setopt($ch, CURLOPT_URL, "{$url}");
    //访问WWWWW
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    // 对认证证书来源的检查
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    // 模拟用户使用的浏览器
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    // 使用自动跳转
    curl_setopt($ch, CURLOPT_POST, 1);
    // 发送一个常规的Post请求
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    //这个是解释gzip内容.................
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    // 设置超时限制防止死循环
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 显示返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 获取的信息以文件流的形式返回
    $data = curl_exec($ch);
    curl_close($ch);
    $json_Class = json_decode($data);
    $json_Array = json_decode($data, true);
    return $json_Array['' . $u . ''];
}
function api_0($url)
{
    header("Content-Type: text/html; charset=UTF-8");
    $header = array("content-type: application/x-www-form-urlencoded; charset=utf-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    //设置http头
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    //设置为客户端支持gzip压缩
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    //设置连接等待时间
    curl_setopt($ch, CURLOPT_URL, "{$url}");
    //访问WWWWW
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    // 对认证证书来源的检查
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    // 模拟用户使用的浏览器
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    // 使用自动跳转
    curl_setopt($ch, CURLOPT_POST, 1);
    // 发送一个常规的Post请求
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    //这个是解释gzip内容.................
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    // 设置超时限制防止死循环
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 显示返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 获取的信息以文件流的形式返回
    $data = curl_exec($ch);
    curl_close($ch);
    $json_Class = json_decode($data);
    $json_Array = json_decode($data, true);
    return $json_Array;
}
//支付宝配置
function paraFilter($para)
{
    $para_filter = array();
    while (list($key, $val) = each($para)) {
        if ($key == "sign" || $key == "sign_type" || $val == "") {
            continue;
        } else {
            $para_filter[$key] = $para[$key];
        }
    }
    return $para_filter;
}
function argSort($para)
{
    ksort($para);
    reset($para);
    return $para;
}
/**
 * 把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串，并对字符串做urlencode编码
 * @param $para 需要拼接的数组
 * return 拼接完成以后的字符串
 */
function createLinkstringUrlencode($para)
{
    $arg = "";
    while (list($key, $val) = each($para)) {
        $arg .= $key . "=" . urlencode($val) . "&";
    }
    //去掉最后一个&字符
    $arg = substr($arg, 0, count($arg) - 2);
    //如果存在转义字符，那么去掉转义
    if (get_magic_quotes_gpc()) {
        $arg = stripslashes($arg);
    }
    return $arg;
}
/* *
 * 支付宝接口公用函数
* 详细：该类是请求、通知返回两个文件所调用的公用函数核心处理文件
* 版本：3.3
* 日期：2012-07-19
* 说明：
* 以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
*/
/**
 * 把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstring($para)
{
    $arg = "";
    while (list($key, $val) = each($para)) {
        $arg .= $key . "=" . $val . "&";
    }
    //去掉最后一个&字符
    $arg = substr($arg, 0, count($arg) - 2);
    //如果存在转义字符，那么去掉转义
    if (get_magic_quotes_gpc()) {
        $arg = stripslashes($arg);
    }
    return $arg;
}
/**
 * 签名字符串
 * @param $prestr 需要签名的字符串
 * @param $key 私钥
 * return 签名结果
 */
function md5Sign($prestr, $key)
{
    $prestr = $prestr . $key;
    return md5($prestr);
}
function md5Verify($prestr, $sign, $key)
{
    $prestr = $prestr . $key;
    $mysgin = md5($prestr);
    if ($mysgin == $sign) {
        return true;
    } else {
        return false;
    }
}
/**
 * 远程获取数据，GET模式
 * 注意：
 * 1.使用Crul需要修改服务器中php.ini文件的设置，找到php_curl.dll去掉前面的";"就行了
 * 2.文件夹中cacert.pem是SSL证书请保证其路径有效，目前默认路径是：getcwd().'\\cacert.pem'
 * @param $url 指定URL完整路径地址
 * @param $cacert_url 指定当前工作目录绝对路径
 * return 远程输出的数据
 */
function getHttpResponseGET($url, $cacert_url)
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    // 过滤HTTP头
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    // 显示输出结果
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    //SSL证书认证
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    //严格认证
    curl_setopt($curl, CURLOPT_CAINFO, $cacert_url);
    //证书地址
    $responseText = curl_exec($curl);
    //var_dump( curl_error($curl) );//如果执行curl过程中出现异常，可打开此开关，以便查看异常内容
    curl_close($curl);
    return $responseText;
}
function www()
{
    return preg_replace("/www\\./", "", $_SERVER['HTTP_HOST']);
}
//判断pc端
function WEB()
{
    $s = (include 'app/extra/web.php');
    if (isMobile() == true) {
        //移动
        return 'app/template/wap/' . $s['WAP'] . '/';
    } else {
        //pc端
        return 'app/template/pc/' . $s['WEB'] . '/';
    }
}
function pc()
{
    return 'app/template/pc/default_pc/';
}
function MBPC()
{
    $s = (include 'app/extra/web.php');
    if (cms('default') == $s['WEB']) {
        return $s['WEB'];
    } else {
        return 'default_pc';
    }
}
function MBWAP()
{
    $s = (include 'app/extra/web.php');
    if (cms('defaultwap') == $s['WAP']) {
        return $s['WAP'];
    } else {
        return 'default_wap';
    }
}
function getFile($url, $save_dir = '', $filename = '', $type = 0)
{
    if (trim($url) == '') {
        return false;
    }
    if (trim($save_dir) == '') {
        $save_dir = './';
    }
    if (0 !== strrpos($save_dir, '/')) {
        $save_dir .= '/';
    }
    if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
        return false;
    }
    if ($type) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $content = curl_exec($ch);
        curl_close($ch);
    } else {
        ob_start();
        readfile($url);
        $content = ob_get_contents();
        ob_end_clean();
    }
    $size = strlen($content);
    $fp2 = @fopen($save_dir . $filename, 'a');
    fwrite($fp2, $content);
    fclose($fp2);
    unset($content, $url);
}
function layubb($Text) {
	$face = ["[微笑]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/5c/huanglianwx_thumb.gif", "[嘻嘻]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/0b/tootha_thumb.gif", "[哈哈]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6a/laugh.gif", "[可爱]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/14/tza_thumb.gif", "[可怜]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/af/kl_thumb.gif", "[挖鼻]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/0b/wabi_thumb.gif", "[吃惊]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/f4/cj_thumb.gif", "[害羞]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6e/shamea_thumb.gif", "[挤眼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/c3/zy_thumb.gif", "[闭嘴]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/29/bz_thumb.gif", "[鄙视]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/71/bs2_thumb.gif", "[爱你]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6d/lovea_thumb.gif", "[泪]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/9d/sada_thumb.gif", "[偷笑]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/19/heia_thumb.gif", "[亲亲]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/8f/qq_thumb.gif", "[生病]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/b6/sb_thumb.gif", "[太开心]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/58/mb_thumb.gif", "[白眼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d9/landeln_thumb.gif", "[右哼哼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/98/yhh_thumb.gif", "[左哼哼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6d/zhh_thumb.gif", "[嘘]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/a6/x_thumb.gif", "[衰]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/af/cry.gif", "[委屈]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/73/wq_thumb.gif", "[吐]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/9e/t_thumb.gif", "[哈欠]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/cc/haqianv2_thumb.gif", "[抱抱]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/27/bba_thumb.gif", "[怒]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/7c/angrya_thumb.gif", "[疑问]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/5c/yw_thumb.gif", "[馋嘴]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/a5/cza_thumb.gif", "[拜拜]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/70/88_thumb.gif", "[思考]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/e9/sk_thumb.gif", "[汗]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/24/sweata_thumb.gif", "[困]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/40/kunv2_thumb.gif", "[睡]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/96/huangliansj_thumb.gif", "[钱]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/90/money_thumb.gif", "[失望]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/0c/sw_thumb.gif", "[酷]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/40/cool_thumb.gif", "[色]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/20/huanglianse_thumb.gif", "[哼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/49/hatea_thumb.gif", "[鼓掌]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/36/gza_thumb.gif", "[晕]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d9/dizzya_thumb.gif", "[悲伤]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/1a/bs_thumb.gif", "[抓狂]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/62/crazya_thumb.gif", "[黑线]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/91/h_thumb.gif", "[阴险]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6d/yx_thumb.gif", "[怒骂]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/60/numav2_thumb.gif", "[互粉]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/89/hufen_thumb.gif", "[心]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/40/hearta_thumb.gif", "[伤心]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/ea/unheart.gif", "[猪头]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/58/pig.gif", "[熊猫]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/6e/panda_thumb.gif", "[兔子]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/81/rabbit_thumb.gif", "[ok]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d6/ok_thumb.gif", "[耶]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d9/ye_thumb.gif", "[good]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d8/good_thumb.gif", "[NO]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/ae/buyao_org.gif", "[赞]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d0/z2_thumb.gif", "[来]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/40/come_thumb.gif", "[弱]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d8/sad_thumb.gif", "[草泥马]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/7a/shenshou_thumb.gif", "[神马]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/60/horse2_thumb.gif", "[囧]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/15/j_thumb.gif", "[浮云]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/bc/fuyun_thumb.gif", "[给力]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/1e/geiliv2_thumb.gif", "[围观]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/f2/wg_thumb.gif", "[威武]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/70/vw_thumb.gif", "[奥特曼]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/bc/otm_thumb.gif", "[礼物]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/c4/liwu_thumb.gif", "[钟]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d3/clock_thumb.gif", "[话筒]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/9f/huatongv2_thumb.gif", "[蜡烛]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/d9/lazhuv2_thumb.gif", "[蛋糕]" => "http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/3a/cakev2_thumb.gif"];
	$Text = preg_replace("/a\\(([\\s\\S]+?)\\)\\[([\\s\\S]*?)\\]/is", "<a href=\"\\1\" target=_blank>\\2</a>", $Text);
	$Text = preg_replace("/@(\\S+)(\\s+?|\$)/is", "@<a href=\"javascript:;\" class=\"fly-aite\">\\1</a>\\2", $Text);
	$Text = preg_replace("/img\\[([^\\s]+?)\\]/is", "<img src=\"\\1\" />", $Text);
	$Text = preg_replace("/\\[(pre|hr|div|span|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h1|h2|h3|h4|h5)([\\s\\S]*?)\\]/is", "<\\1>", $Text);
	$Text = preg_replace("/\\[\\/(pre|hr|div|span|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h1|h2|h3|h4|h5)([\\s\\S]*?)\\]/is", "</\\1>", $Text);
	$Text = preg_replace("/\\n/is", "<br/>", $Text);
	$replacement = '[${1}]';
        $Text = preg_replace_callback("/face\[([^\s\[\]]+?)\]/is", function($replacement) use($face) {
            return "<img alt=\"{$replacement[1]}\" title=\"{$replacement[1]}\" src=\"{$face["[{$replacement[1]}]"]}\">";
        }, $Text);
	return $Text;
}
/** 
 * 判断手机号码是否合法 
 * @param $mobile 手机号码 
 * @return bool 
 */
function check_mobile($mobile)
{
    // $pattern = '/^(1(([35][0-9])|(47)|[8][0126789]))\d{8}$/';
    $pattern = '/^(0|86|17951)?(888|13[0-9]|15[012356789]|17[0-9]|111|18[0-9]|14[57])[0-9]{8}$/';
    if (preg_match($pattern, $mobile)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
/** 
 * 判断邮箱地址是否合法 
 * @param $email 
 * @return bool 
 */
function checkEmail($email)
{
    $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)\$/i";
    if (preg_match($pattern, $email)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
/** 
 * 判断用户名是否合法 
 * @param $name 小写字母开头，只能包含小写字母3-16位 
 * @return bool 
 */
function checkUsername($name)
{
    $patten = '/^[a-z]{3,12}$/';
    if (preg_match($patten, $name)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
/** 
 * 判断真实姓名是否合法 
 * @param $realname 
 * @return bool 
 */
function checkRealname($realname)
{
    $patten = '/^[\\x{4e00}-\\x{9fa5}]+$/u';
    if (preg_match($patten, $realname)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
/** 
 * 判断IP地址是否合法 
 * @param $ip 
 * @return bool 
 */
function checkIP($ip)
{
    $patten = "/^(((1?\\d{1,2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((1?\\d{1,2})|(2[0-4]\\d)|(25[0-5]))\$/";
    if (preg_match($patten, $ip)) {
        return true;
    } else {
        return false;
    }
}
h('phpcommon');
//输出插件配置值
function ads($u, $s)
{
    $c = fun_sc_p('addons', array('name' => $u), 'config');
    $arr = json_decode($c, true);
    return $arr[$s];
}
//随机获取数组
function sjsz($ks)
{
    $a = explode(",", $ks);
    $key = array_rand($a, 1);
    return $a[$key];
}
//相关数据查询
function fun_ks($set, $so, $ks, $map, $x)
{
    $data[$so] = ['like', '%' . $ks . '%'];
    $wanneng = Db::name($set)->where($data)->where($map)->orderRaw('rand()')->limit($x)->select();
    return $wanneng;
}
//转换数组输出
function exps($ks)
{
    $a = explode(",", $ks);
    return $a;
}
//获取完整URL
function get_url()
{
    $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
    //根据当前端口，判断是http还是https
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
    //获取当前网页地址
    $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
    //获取path_info信息
    $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : $path_info);
    //获取除域名外的完整URL,获取不到php文件（如启用了pathinfo)，就获取文件实际地址和参数
    $url = $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url;
    return $url;
}
//xss过滤
function clean_xss(&$string, $low = False)
{
    if (!is_array($string)) {
        $string = trim($string);
        $string = strip_tags($string);
        $string = htmlspecialchars($string);
        if ($low) {
            return True;
        }
        $string = str_replace(array('"', "\\", "'", "/", "..", "../", "./", "//"), '', $string);
        $no = '/%0[0-8bcef]/';
        $string = preg_replace($no, '', $string);
        $no = '/%1[0-9a-f]/';
        $string = preg_replace($no, '', $string);
        $no = '/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]+/S';
        $string = preg_replace($no, '', $string);
        return True;
    }
    $keys = array_keys($string);
    foreach ($keys as $key) {
        clean_xss($string[$key]);
    }
}
//检测域名格式
function CheckUrl($C_url)
{
    $str = "/^http(s?):\\/\\/(?:[A-za-z0-9-]+\\.)+[A-za-z]{2,4}(?:[\\/\\?#][\\/=\\?%\\-&~`@[\\]\\':+!\\.#\\w]*)?\$/";
    if (!preg_match($str, $C_url)) {
        return false;
    } else {
        return true;
    }
}
error_reporting(E_ERROR | E_PARSE);
//获取pc模板设置值
function cmspc($s)
{
    $url = 'app/template/pc/' . cms('default') . '/Cms_pc.php';
    $info = (include $url);
    return $info[$s];
}
//获取wap模板设置值
function cmswap($s)
{
    $url = 'app/template/wap/' . cms('defaultwap') . '/Cms_wap.php';
    $info = (include $url);
    return $info[$s];
}
//内容图片本地化
function getCurContent($content)
{
    //匹配图片地址
    preg_match_all('/((http|https):\\/\\/)+(\\w+\\.)+(\\w+)[\\w\\/\\.\\-]*(jpg|gif|png)/', $content, $img_array);
    //移除重复的Url
    $img_array = array_unique($img_array[0]);
    if ($img_array != '') {
        $imgUrl = DS . 'uploads' . DS . date("Ymd") . DS;
        $imgPath = ROOT_PATH . $imgUrl;
        $htd = new Http();
        foreach ($img_array as $key => $value) {
            //获取hash
            $md5 = strtolower($htd->getHash($value, true));
            $filemode = Db::name('file');
            $n = $filemode->where('md5', $md5)->find();
            $realpath = '';
            if (empty($n)) {
                $itype = substr(strrchr($value, '.'), 1);
                $milliSecondN = md5(microtime(true));
                $rndFileName = $imgPath . $milliSecondN . '.' . $itype;
                $fileurl = $imgUrl . $milliSecondN . '.' . $itype;
                $rs = $htd->http_down($value, $rndFileName);
                //抓取成功
                if ($rs) {
                    $path = str_replace("\\", "/", $fileurl);
                    $realpath = WEB_URL . $path;
                    //写入数据库
                    $data['sha1'] = sha1($rndFileName);
                    $data['md5'] = md5($rndFileName);
                    $data['create_time'] = time();
                    $data['size'] = filesize($rndFileName);
                    $data['name'] = $milliSecondN . '.' . $itype;
                    $data['ext'] = $itype;
                    $data['savepath'] = $realpath;
                    $data['savename'] = $milliSecondN . '.' . $itype;
                    Db::name('file')->insert($data);
                }
            } else {
                $realpath = $n['savepath'];
            }
            $content = str_replace($value, $realpath, $content);
        }
    }
    return $content;
}
function mymuban_pc()
{
    $home = file_get_contents(jiami('613cRodzdemdJ6bGa24LTQEGY0wz4V+eDLLaKFk6ibvrc2jFf21nh07UyvM5quei75F4aReRYEjfy+CT87FTZRUMFoCjDw', 'DECODE', 'api', 0));
    $json_Class = json_decode($home);
    $json_Array = json_decode($home, true);
    return $json_Array;
}
function mymuban_wap()
{
    $home = file_get_contents(jiami('b423OAgmyZF/sxiEMaXSf7NfadAWkBqL8cu6ACk6uqmWgYMvvhqGBppGI6Ac9Fdo4MCOeGz5q0zze0QfMyCo7ZiLErmIZOk', 'DECODE', 'api', 0));
    $json_Class = json_decode($home);
    $json_Array = json_decode($home, true);
    return $json_Array;
}
function myaddons()
{
    $home = file_get_contents(pa('UmNdrRIs6C-lDj-vmRXgaifY0ktyyPB83ieD%3DTHCln9splMdmQsQ5ROZ5hM20'));
    $json_Class = json_decode($home);
    $json_Array = json_decode($home, true);
    return $json_Array;
}
if (ads('mobileurl', 'open') == 1) {
    if (isMobile() == true) {
        if (strpos(get_url(), ads('mobileurl', 'urlwap')) == false) {
            $getregex = '/' . $_SERVER['HTTP_HOST'] . '/';
            $geturl = preg_replace($getregex, '' . ads('mobileurl', 'urlwap') . '', get_url());
            header(sprintf('Location:%s', '' . $geturl . ''));
        }
    } else {
        if (strpos(get_url(), ads('mobileurl', 'urlpc')) == false) {
            $getregex = '/' . $_SERVER['HTTP_HOST'] . '/';
            $geturl = preg_replace($getregex, '' . ads('mobileurl', 'urlpc') . '', get_url());
            header(sprintf('Location:%s', '' . $geturl . ''));
        }
    }
}
/*
自定义数据分割例如
{volist name=":vo($c.content,PHP_EOL,'$')" id="v"}
{$v.id}-{$v.name}<br>
{/volist}
*/
function vo($ks,$mu,$my)
{
    $arr = explode($mu, $ks);
    for ($i = 0; $i < count($arr); $i++) {
        $arr2 = explode($my, $arr[$i]);
        $chaxun[$i]['id'] = $arr2[0];
        $chaxun[$i]['name'] = $arr2[1];
        $chaxun[$i]['urls'] = $i;
    }
    return $chaxun;
}
function expz($ks,$k)
{
    $a = explode($k, $ks);
    return $a;
}
function getImgList($content,$order='ALL'){
	$html_string = htmlspecialchars_decode($content);
	$pattern = "/<[img|IMG].*?src=[\\'|\"](.*?(?:[\\.gif|\\.jpg|\\.png]))[\\'|\"].*?[\\/]?>/";
	preg_match_all($pattern, $html_string, $match);
 
	if(isset($match[1])&&!empty($match[1])){
		if($order==='ALL'){
			return $match[1];
		}
		if(is_numeric($order)&&isset($match[1][$order])){
			return $match[1][$order];
		}
	}
	return [];
}
//查询相关统计数量
function cat($set,$so, $ks,$map) {
	$data[$so]= ['like', '%'.$ks.'%'];
	$wanneng = Db::name($set)->where($data)->where($map)->count();
	return $wanneng;
}
//随机栏目下推荐
function fun_sj_id($set, $open, $a, $x)
{
    $wanneng = Db::name($set)->alias('f')->join('cate c', 'c.id=f.tid')->field('f.*,c.id as cid')->where($open)->where("f.tid={$a} or c.tid={$a}")->orderRaw('rand()')->limit($x)->select();
    return $wanneng;
}
function getpic($content){
	return preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $content);
}